<?php

//全局bootstrap事件
use EasySwoole\EasySwoole\Config;
use EasySwoole\EasySwoole\Core;
use EasySwoole\ORM\Db\Connection;
use EasySwoole\ORM\DbManager;

date_default_timezone_set('Asia/Shanghai');

//用户想要执行自己需要的初始化业务代码：如 注册命令行支持、全局通用函数、启动前调用协程 API等功能，就可以在 bootstrap.php 中进行编写实现。
\EasySwoole\Command\CommandManager::getInstance()->addCommand(new \App\Command\Generate());

//在 bootstrap 事件 中注册自定义命令。
require_once './App/Common/constant.php';
require_once './App/Common/functions.php';

Core::getInstance()->initialize();
$config = new \EasySwoole\ORM\Db\Config(Config::getInstance()->getConf('MYSQL'));
$config->setReturnCollection(true);
DbManager::getInstance()->addConnection(new Connection($config));
DbManager::getInstance()->onQuery(function (EasySwoole\ORM\Db\Result $res, EasySwoole\Mysqli\QueryBuilder $builder, $start) {
    \EasySwoole\EasySwoole\Logger::getInstance()->debug('-------------开始-----------------');
    \EasySwoole\EasySwoole\Logger::getInstance()->debug('查询时间: '. bcsub(time(), $start, 3));
    \EasySwoole\EasySwoole\Logger::getInstance()->debug($builder->getLastQuery());
    \EasySwoole\EasySwoole\Logger::getInstance()->debug(PHP_EOL.print_r($res->getResult(), true));
    \EasySwoole\EasySwoole\Logger::getInstance()->debug('-------------结束-----------------');
});
